package com.example.administrator.zkdemo.utils;

/**
 * Created with Android Studio.
 * 描述: ${DESCRIPTION}
 * Date: 2018/11/21
 * Time: 16:38
 *
 * @author 晏琦云
 * @version ${VERSION}
 */

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;
import android.support.annotation.NonNull;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

import java.security.MessageDigest;

public class CircleTransform extends BitmapTransformation {
    public CircleTransform(Context paramContext) {
    }

    public static Bitmap circleCrop(BitmapPool paramBitmapPool, Bitmap paramBitmap) {
        if (paramBitmap == null)
            return null;
        int i = Math.min(paramBitmap.getWidth(), paramBitmap.getHeight());
        Bitmap localBitmap = Bitmap.createBitmap(paramBitmap, (paramBitmap.getWidth() - i) / 2, (paramBitmap.getHeight() - i) / 2, i, i);
        paramBitmap = paramBitmapPool.get(i, i, Bitmap.Config.ARGB_8888);
        paramBitmapPool = paramBitmap;
        if (paramBitmap == null)
            paramBitmapPool = Bitmap.createBitmap(i, i, Bitmap.Config.ARGB_8888);
        paramBitmap = new Canvas(paramBitmapPool);
        Paint localPaint = new Paint();
        localPaint.setShader(new BitmapShader(localBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
        localPaint.setAntiAlias(true);
        float f = i / 2.0F;
        paramBitmap.drawCircle(f, f, f, localPaint);
        return paramBitmapPool;
    }

    public String getId() {
        return getClass().getName();
    }

    protected Bitmap transform(BitmapPool paramBitmapPool, Bitmap paramBitmap, int paramInt1, int paramInt2) {
        return circleCrop(paramBitmapPool, paramBitmap);
    }

    @Override
    public void updateDiskCacheKey(@NonNull MessageDigest messageDigest) {

    }
}